# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

	def only_for_admin
		if logged_in? && @signed_user.is_admin?
			yield
		end
	end

	def display_sign_action
		if logged_in?
			"#{link_to('&deg;Account', user_path(@signed_user))} " +
			"#{link_to('&deg;Sign-Out', signout_path)}"
		else
			"#{link_to('&deg;Sign-In', signin_path)} " +
			"#{link_to('&deg;Create-account', signup_path)}"
		end
	end

	def display_controller_depend_basic_link(name, url, ctrl)
		link_to "&deg;#{name}", url, :class => (params[:controller] == ctrl) ? "hovered" : "basic"
	end

	def display_updated_time(inst)
		"<span class='color_369'>#{inst.updated_at.localtime.to_formatted_s(:us)}</span>"
	end

	def display_owner(inst)
		login = (inst.user.blank?) ? "Guest" : inst.user.login
		"<span class='color_369'>#{login}</span>"
	end

	def flash_messages
		if flash[:error]
			fl = "<div class=\"errorExplanation\" id=\"errorExplanation\">#{flash[:error]}</div>"
			flash[:error] = nil
		elsif flash[:notice]
			fl = "<div id=\"noticeExplanation\" class=\"noticeExplanation\">#{flash[:notice]}</div>"
			flash[:notice] = nil
		end

		fl
	end

end
